﻿'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose:
' rckid is often a concatentation of site, building, floor,
' intlocation, and cabinetno. we keep the parameters
' discrete so that we can query them
'
' we allow two special cases for the cabinet records
' a.) if the rckid is xxx then it is a virtual rack
'     so that we can assign a component/node to a specific
'     point on the page (such as using wap's)
' b.) the slot count is used when using the rack add-in
'     if the value is zero then we load a third party master
'     from the associated stencil
'
'
'*******************************************************************



Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging

Imports Visio = Microsoft.Office.Interop.Visio
Imports System.Runtime.InteropServices

Imports System
Imports System.ComponentModel
Imports System.Collections.Generic

Imports System.Collections.ObjectModel


Imports System.Data
Imports System.Array
Imports System.Data.Common
Imports System.Xml
Imports System.IO

Imports System.Drawing


Imports DC_Rack.Support.clsVisioSupport
Imports DC_Rack.Objects.clsDC_RackData




Public Class clsAttrCabinet

#Region "notes"

    ' within a row a position can only be once (index row position)
    ' within a site a rack id can only be once (index siterackname)

#End Region

#Region " Properties and definitions "


    Public m_db As Database
    Public m_ds As DataSet
    Public m_dt As DataTable

    Public m_tempds As DataSet
    Public m_dttemp As DataTable

    Public m_dc As dc_Cabinet
    Public m_oc As Collection(Of dc_Cabinet)

    Private strUserId As String


    Public m_clsVisio As DC_Rack.Support.clsVisioSupport

    Private m_deleteCommand As DbCommand
    Private m_insertCommand As DbCommand
    Private m_updateCommand As DbCommand

    Public Const readAll As String = "selectTblAttrCabinet"

    ' who am I
    Private myEnum As DC_RackTables = DC_RackTables.tblAttrCabinet

#End Region

#Region " Move/Transform Data "

    '
    ' create columns
    '
    Public Sub CreateTableColumns(ByRef tempTable As DataTable)

        Dim newDC As dc_Cabinet = New dc_Cabinet(strUserId)

        Try

            Dim colRckKey As New System.Data.DataColumn
            colRckKey.ColumnName = "rckKey"
            colRckKey.DataType = GetType(Integer)
            colRckKey.DefaultValue = newDC.rckKey
            tempTable.Columns.Add(colRckKey)

            Dim colRckCompKey As New System.Data.DataColumn
            colRckCompKey.ColumnName = "rckCompKey"
            colRckCompKey.DataType = GetType(Integer)
            colRckCompKey.DefaultValue = newDC.rckCompKey
            tempTable.Columns.Add(colRckCompKey)

            Dim colRckRowKey As New System.Data.DataColumn
            colRckRowKey.ColumnName = "rckRowKey"
            colRckRowKey.DataType = GetType(Integer)
            colRckRowKey.DefaultValue = newDC.rckRowKey
            tempTable.Columns.Add(colRckRowKey)

            Dim colRckRowPos As New System.Data.DataColumn
            colRckRowPos.ColumnName = "rckRowPos"
            colRckRowPos.DataType = GetType(Integer)
            colRckRowPos.DefaultValue = newDC.rckRowPos
            tempTable.Columns.Add(colRckRowPos)

            Dim colRckGrid As New System.Data.DataColumn
            colRckGrid.ColumnName = "rckGrid"
            colRckGrid.DataType = GetType(String)
            tempTable.Columns.Add(colRckGrid)

            Dim colRckDescription As New System.Data.DataColumn
            colRckDescription.ColumnName = "rckDescription"
            colRckDescription.DataType = GetType(String)
            tempTable.Columns.Add(colRckDescription)

            Dim colRckType As New System.Data.DataColumn
            colRckType.ColumnName = "rckType"
            colRckType.DataType = GetType(String)
            colRckType.DefaultValue = newDC.rckType
            tempTable.Columns.Add(colRckType)

            Dim colRckComments As New System.Data.DataColumn
            colRckComments.ColumnName = "rckComments"
            colRckComments.DataType = GetType(String)
            colRckComments.DefaultValue = newDC.rckComments
            tempTable.Columns.Add(colRckComments)

            Dim colRckLastUpdate As New System.Data.DataColumn
            colRckLastUpdate.ColumnName = "rckLastUpdate"
            colRckLastUpdate.DataType = GetType(Date)
            colRckLastUpdate.DefaultValue = newDC.rckLastUpdate
            tempTable.Columns.Add(colRckLastUpdate)

            Dim colRckLastEdit As New System.Data.DataColumn
            colRckLastEdit.ColumnName = "rckLastEdit"
            colRckLastEdit.DataType = GetType(String)
            colRckLastEdit.DefaultValue = newDC.rckLastEdit
            tempTable.Columns.Add(colRckLastEdit)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If newDC IsNot Nothing Then
            newDC = Nothing
        End If

    End Sub

    '
    ' use this initially for adding rows
    '
    Public Sub movePropertiesToDataRow _
            (ByRef tempRow As DataRow, _
             ByVal tempDC As dc_Cabinet)

        Try

            With tempDC
                tempRow.SetField("rckKey", .rckKey)
                tempRow.SetField("rckRowKey", .rckRowKey)
                tempRow.SetField("rckRowPos", .rckRowPos)
                tempRow.SetField("rckGrid", .rckGrid)
                tempRow.SetField("rckDescription", .rckDescription)
                tempRow.SetField("rckType", .rckType)
                tempRow.SetField("rckComments", .rckComments)
                tempRow.SetField("rckLastUpdate", .rckLastUpdate)
                tempRow.SetField("rckLastEdit", strUserId)
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataRowToProperties _
            (ByVal tempRow As DataRow)

        Try

            With m_dc
                .initProperties()
                .rckKey = tempRow.Item("rckKey")
                .rckRowKey = tempRow.Item("rckRowKey")
                .rckRowPos = tempRow.Item("rckRowPos")
                .rckGrid = tempRow.Item("rckGrid")
                .rckDescription = tempRow.Item("rckDescription")
                .rckType = tempRow.Item("rckType")
                .rckComments = tempRow.Item("rckComments")
                .rckLastUpdate = tempRow.Item("rckLastUpdate")
                .rckLastEdit = tempRow.Item("rckLastEdit")
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataRowToProperties _
            (ByVal tempRow As DataRow, _
             ByRef tempDC As dc_Cabinet)

        Try

            With tempDC
                .initProperties()
                .rckKey = tempRow.Item("rckKey")
                .rckRowKey = tempRow.Item("rckRowKey")
                .rckRowPos = tempRow.Item("rckRowPos")
                .rckGrid = tempRow.Item("rckGrid")
                .rckDescription = tempRow.Item("rckDescription")
                .rckType = tempRow.Item("rckType")
                .rckComments = tempRow.Item("rckComments")
                .rckLastUpdate = tempRow.Item("rckLastUpdate")
                .rckLastEdit = tempRow.Item("rckLastEdit")
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataTableToObservableCollection _
                (ByVal dtTemp As DataTable)

        Try

            If 0 < dtTemp.Rows.Count Then

                If m_oc IsNot Nothing Then
                    m_oc = Nothing
                    m_oc = New Collection(Of dc_Cabinet)
                Else
                    m_oc = New Collection(Of dc_Cabinet)
                End If

                Dim drTemp As DataRow
                Dim dcTemp As dc_Cabinet
                For Each drTemp In dtTemp.Rows
                    dcTemp = New dc_Cabinet
                    moveDataRowToProperties(drTemp, dcTemp)
                    m_oc.Add(dcTemp)
                Next

            End If

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Function moveDataTableToXML() As XmlDocument

        Dim writer = New System.IO.StringWriter
        Dim m_dt_xml As Xml.XmlDocument = Nothing

        Try


            m_dt.WriteXml(writer, XmlWriteMode.WriteSchema, True)
            m_dt_xml = Nothing
            m_dt_xml = New Xml.XmlDocument
            m_dt_xml.LoadXml(writer.ToString)

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally

            writer = Nothing

        End Try

        Return m_dt_xml


    End Function


#End Region

#Region " Standard Database Commands "

    '
    '
    '
    Private Sub buildInsertCabinetCommand()


        Try
            m_insertCommand = m_db.GetStoredProcCommand("insertAttrCabinet")

            Dim cmdActive As DbCommand
            cmdActive = m_insertCommand

            '	@rckSiteKey int,
            m_db.AddInParameter(cmdActive, "rckCompKey", DbType.Int32, "rckCompKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckRowKey", DbType.Int32, "rckRowKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckRowPos", DbType.Int16, "rckRowPos", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckGrid", DbType.String, "rckGrid", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckDescription", DbType.String, "rckDescription", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckType", DbType.String, "rckType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckComments", DbType.String, "rckComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckLastUpdate", DbType.Date, "rckLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckLastEdit", DbType.String, "rckLastEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    '
    '
    Private Sub buildUpdateCabinetCommand()


        Try
            m_updateCommand = m_db.GetStoredProcCommand("updateAttrCabinet")

            Dim cmdActive As DbCommand = m_updateCommand

            m_db.AddInParameter(cmdActive, "rckKey", DbType.Int32, "rckKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckCompKey", DbType.Int32, "rckCompKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckRowKey", DbType.Int32, "rckRowKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckRowPos", DbType.Int16, "rckRowPos", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckGrid", DbType.String, "rckGrid", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckDescription", DbType.String, "rckDescription", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckType", DbType.String, "rckType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckComments", DbType.String, "rckComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckLastUpdate", DbType.Date, "rckLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "rckLastEdit", DbType.String, "rckLastEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub

    '
    '
    '
    Private Sub buildDeleteCabinetCommand()


        Try
            m_deleteCommand = m_db.GetStoredProcCommand("deleteAttrCabinet")

            Dim cmdActive As DbCommand = m_deleteCommand

            '	@rckKey int,
            m_db.AddInParameter(cmdActive, "rckKey", DbType.Int32, "rckKey", DataRowVersion.Current)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub

    '
    '
    '
    Public Function dbUpdateDataSet() As Int16

        Dim rowsAffected As Int16 = 0

        Try

            rowsAffected = m_db.UpdateDataSet(m_ds, dc_racktables.tblattrcabinet.tostring, _
                                        m_insertCommand, _
                                        m_updateCommand, _
                                        m_deleteCommand, _
                                        UpdateBehavior.Standard)
            'msgbox rowsAffected

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

        Return rowsAffected

    End Function

    '
    '
    '
    Public Sub initDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_ds Is Nothing Then
                m_ds = New DataSet
            Else
                m_ds = Nothing
                m_ds = New DataSet
            End If
            m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_dt Is Nothing Then
                m_dt = New DataTable
            Else
                m_dt = Nothing
                m_dt = New DataTable
            End If

            If m_oc Is Nothing Then
                m_oc = New Collection(Of dc_Cabinet)
            Else
                m_oc = Nothing
                m_oc = New Collection(Of dc_Cabinet)
            End If

            If m_dc IsNot Nothing Then
                m_dc = Nothing
                m_dc = New dc_Cabinet(strUserId)
            Else
                m_dc = New dc_Cabinet(strUserId)
            End If

            CreateTableColumns(m_dt)
            m_dt.TableName = dc_racktables.tblattrcabinet.tostring
            m_ds.Tables.Add(m_dt)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub

    '
    '
    '
    Private Sub initTempDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_tempds Is Nothing Then
                m_tempds = New DataSet
            Else
                m_tempds = Nothing
                m_tempds = New DataSet
            End If
            m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_dttemp Is Nothing Then
                m_dttemp = New DataTable
            Else
                m_dttemp = Nothing
                m_dttemp = New DataTable
            End If



            ' cannot create field names because we want to use this one
            ' for querying views
            m_dt.TableName = "temp"
            m_ds.Tables.Add(m_dttemp)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub


    '
    ' create a record based on property values move it to the generic datatable
    ' then copy the table to the database
    '
    Public Function addAttrCabinetDataSourceRecord _
                (ByVal tempDC As dc_Cabinet, _
                 Optional ByVal blnSilent As Boolean = False) _
                 As Integer

        Dim intRowsAffected As Integer = 0

        Try

            initDataSetAndTable()

            Dim m_dr As DataRow = m_ds.Tables(dc_racktables.tblattrcabinet.tostring).NewRow
            movePropertiesToDataRow(m_dr, tempDC)
            m_ds.Tables(dc_racktables.tblattrcabinet.tostring).Rows.Add(m_dr)
            intRowsAffected = dbUpdateDataSet()

            If blnSilent = False Then
                MsgBox("DataRowsUpated = " & intRowsAffected)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return intRowsAffected

    End Function




#End Region

#Region " database calls "

    '
    '
    '
    Public Sub dbSelectAllCabinets()


        Try


            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand(readAll)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblattrcabinet.tostring)

            m_dt = m_ds.Tables(dc_racktables.tblattrcabinet.tostring)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' Retrieve the cabinet, comp, location data
    '
    Public Sub dbSelectViewCabinets()


        Try

            initDataSetAndTable()


            Dim strViewTable As String = "tblViewCabinets"
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectViewCabinets")
            m_db.LoadDataSet(cmd, m_ds, strViewTable)

            m_dt = m_ds.Tables(strViewTable)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub dbSelectCabinetsByRowKey _
        (ByVal lngRowKey As Int32)


        Try

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectCabinetsByRowKey")
            m_db.AddInParameter(cmd, "@RowKey", DbType.Int32, lngRowKey)
            m_db.LoadDataSet(cmd, m_ds, "viewCabinets")

            m_dt = m_ds.Tables("viewCabinets")


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' pass in the collection of componentkeys and return a composite cabinet table
    '
    Public Sub dbBuildCabinetsByURRICollection _
            (ByVal colURRIKeys As Collection(Of clsDC_RackData.rackURRI))


        initTempDataSetAndTable()


        Dim dtTemp As DataTable = New DataTable


        Dim drTemp As DataRow
        Dim intCt As Integer

        Dim colUrriTemp As Collection = New Collection

        Try

            For intCt = 0 To colURRIKeys.Count - 1

                If dtTemp Is Nothing Then
                    dtTemp = New System.Data.DataTable
                Else
                    dtTemp = Nothing
                    dtTemp = New System.Data.DataTable
                End If

                dtTemp = dbSelectCabinetViewByRackKey(colURRIKeys(intCt).rckKey)

                If intCt = 0 Then
                    ' for the first rack we need the field names
                    m_dttemp = dtTemp.Copy
                Else
                    ' for the rest of them we only need the data
                    With dtTemp
                        If 0 < dtTemp.Rows.Count Then
                            For Each drTemp In .Rows
                                m_dttemp.ImportRow(drTemp)
                            Next
                        End If
                    End With
                End If
            Next intCt



            If m_ds.Tables("viewCabinets") IsNot Nothing Then
                m_ds.Tables("viewCabinets").Clear()
            End If

            m_dttemp.TableName = "viewCabinets"
            dtTemp.TableName = "viewCabinets"

            m_ds.Tables.Add(m_dttemp.Copy)
            m_dt = m_ds.Tables("viewCabinets").Copy


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' this is the individual query for when we pass in the composite collection
    '
    Public Function dbSelectCabinetViewByRackKey(ByVal intRckKey As Int32) As DataTable

        Dim m_dt1 As DataTable = New DataTable
        Dim m_ds1 As DataSet = New DataSet

        Try

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectCabinetViewByRackCompKey")
            m_db.AddInParameter(cmd, "@rckKey", DbType.Int32, intRckKey)
            m_db.LoadDataSet(cmd, m_ds1, "viewCabinets")
            m_dt1 = m_ds1.Tables("viewCabinets")


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
        End Try

        Return m_dt1

    End Function


    '
    '
    '
    Public Sub dbSelectAttrCabinetByCompKey(ByVal intCompKey As Int32)


        Try

            Dim cmd As DbCommand = m_db.GetStoredProcCommand("selectAttrCabinetByCompKey")
            m_db.AddInParameter(cmd, "@compKey", DbType.Int32, intCompKey)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblattrcabinet.tostring)

            m_dt = m_ds.Tables(dc_racktables.tblattrcabinet.tostring)

            If m_dt.Rows.Count = 1 Then
                Dim m_dr As System.Data.DataRow = m_dt.Rows(0)
                moveDataRowToProperties(m_dr)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
        End Try

    End Sub



#End Region

#Region " constructor "

    '
    '
    '
    Public Sub New()

        Try

            m_db = DatabaseFactory.CreateDatabase()

            strUserId = Environment.UserDomainName & "/" & Environment.UserName

            '
            ' init an object class so that the default constants are available
            ' to the table definitions
            '

            initDataSetAndTable()


            m_clsVisio = New DC_Rack.Support.clsVisioSupport


            buildDeleteCabinetCommand()
            buildInsertCabinetCommand()
            buildUpdateCabinetCommand()



        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try


    End Sub


#End Region

#Region " Visio Attributes "

    Public Sub UpdateAttrCabinetProperties _
            (ByRef visShape As Microsoft.Office.Interop.Visio.Shape, _
             ByVal drCabinet As System.Data.DataRow)


        Try


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub



#End Region



End Class
